const service = require('../../utils/service.js')
const api = require('../../utils/util.js')
Page({
    data: {
        divideList: [],
        shopInfo: {},
        userInfo: {},
        divideInfo: {},
        page: 1,
        hasMoreData: true
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
      let userInfo = wx.getStorageSync('userInfo')
      this.setData({
        userInfo: userInfo
      })
      this.init()
    },

    init: function() {
        let that = this
        api.ajax(service.url('benefit'),{},
        function(res) {
          if(res.code == 0) {
            that.setData({
              divideInfo: res.data
            })
          } else {
            api.toast(res.message)
          }
        })
        this.getDivideList()
    },

    getDivideList: function() {
        let that = this
        api.ajax(service.url('benefitLog'), {
          page: that.data.page
        },
        function(res) {
            if(res.code == 0) {
              if(res.data.length > 0) {
                for(var i = 0, len = res.data.length; i < len; i++) {
                  that.data.divideList.push(res.data[i])
                }
                that.setData({
                  divideList: that.data.divideList,
                  hasMoreData: true
                })
              } else {
                that.setData({
                  hasMoreData: false
                })
              }
            } else {
              api.toast(res.message)
            }
        })
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        let page = this.data.page += 1
        if(this.data.hasMoreData) {
            this.setData({
              page: page
            })
            this.getDivideList()
        } else {
            api.toast('没有更多数据了')
        }
    },
    //--去提现
    goWithdraw: function(){
    	wx.navigateTo({
	      url: '../withdraw/withdraw'
	    })
    },
    //--去提现记录
    goHistory: function(){
    	wx.navigateTo({
	      	url: '../withdraw/history/history'
	    })
    }
})